# **********************OBJ INFO**************************
# Author:YuKalix
# @Time    : 2021-5-11 18:05
# @Site    : 52ziyu.cn
# @File    : TCP.py
# @software: PyCharm
# ******************************************************#!/usr/bin/env python3
#-*- coding:utf-8 -*-

#!/usr/bin/env python3
#-*- coding:utf-8 -*-

from socket import *

class TCP:
    def __init__(self,host, port, buff_size=2048):
        self.__host = host
        self.__port = port
        self.__buff_size=buff_size

        self.__addr = (self.__host, self.__port)

        self.client =  self.client = socket(AF_INET,SOCK_STREAM)

    def init_client(self):
        try:
            self.client.connect(self.__addr)
        except Exception as e:
            if e == OSError:
                self.client.close()
            elif e == TimeoutError:
                raise ("树莓派小车程序没有正常运行")

    def send_message(self, message: bytes, target_address: tuple):
        if not message:
            raise ValueError ("The message is enpyt")

        self.client.send(message)

    def __del__(self):
        self.client.close()


if __name__ == '__main__':
    import ctypes

    so = ctypes.CDLL('./_XiaoRGEEK_SERVO_.so')